package com.kly.module_base.base

import android.R
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.kly.module_base.utils.StatusBarUtil

/**
 * @ClassName: BaseActivity
 * @Description:
 * @Author: You
 */
abstract class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        beforeOnCreate(savedInstanceState)
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        super.onCreate(savedInstanceState)
        StatusBarUtil.setStatusBarTranslucent(this, getLightStatusBarType())
        if (isNeedPaddingTop()) {
            setPaddingTop()
        }
    }

    private fun setPaddingTop() {
        val rootView = window?.decorView?.findViewById<View>(R.id.content)
        rootView?.setBackgroundColor(rootViewBgColor())
        rootView?.setPadding(0, StatusBarUtil.getStatusBarHeight(this), 0, 0)
    }

    protected fun rootViewBgColor(): Int {
        return Color.WHITE
    }

    /**
     * 设置状态栏布局
     *
     * @param colorId
     * */
    protected open fun configPaddingTop() {
        if (isNeedPaddingTop()) {
            setPaddingTop()
        }
    }

    /**
     * 是否需要给跟布局设置一个paddingtop 防止自己的布局到状态栏
     */
    open fun isNeedPaddingTop(): Boolean {
        return true
    }

    open fun beforeOnCreate(savedInstanceState: Bundle?) {

    }

    open fun getLightStatusBarType(): Boolean {
        return true
    }

    protected open fun refreshStatusBar(isLightStatusBar: Boolean) {
        StatusBarUtil.setStatusBarTranslucent(this, isLightStatusBar)
    }

    override fun onDestroy() {
        super.onDestroy()
        onDestroyFrame()
    }

    open fun onDestroyFrame() {

    }
}